<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body style="text-align: center">
<div style="width:250px;height: 100px;background:black;margin: 0 auto; ">

</div>
<div style="width: 500px;height: 200px;background: green;">

</div>
<button onclick="gettime()">gettime</button>
<button onclick="receive()">AJAX请求</button>
</body>
<script>
    
    
  function timeout(ms) {
        return new Promise((resolve, reject) => {
            setTimeout(resolve, ms, 'done');
        }).catch((e) => {console.log(e)});
    }
    function gettime(){
        
        let data=JSON.parse(sessionStorage.getItem('data'));
      
       
        if(data==null){
            var status={
                times:1,
            }
            sessionStorage.setItem('data',JSON.stringify(status))

        }
        else{
            var times=data.times;
            console.log(data.times)
            data.times++;
            sessionStorage.setItem('data',JSON.stringify(data))
        if( data.times>4){
            alert("你登陆次数太频繁！请20秒之后尝试")
            timeout(5000).then((value) => {
                data.times=0;
                sessionStorage.setItem('data',JSON.stringify(data))
            console.log(value);
        });}
        else{
            console.log("get data");
        }

        }
        function receive(){
           
        }
        

      
    }
    console.log('hello')
    const p1=new Promise(function(resolve,reject){
        resolve(new Promise(function(resolve,reject){
          
           setTimeout(()=>resolve(),2000) 
           setTimeout(()=>reject(),10000) 
        }))
    })
    p1.then(function(){
        console.log('ok')
    })
    .catch(function(){
        console.log('falid')
    })

     new Promise(function(resolve,reject){resolve(x+2)}).then(function(){setTimeout(console.log(666),2000)} ).catch(function(){
         
     })
     console.log(999)
     

</script>
</html>